﻿<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>二维码工具测试</title>
    <script type="text/javascript" src="../../Scripts/Jquery/jquery-1.6.2.js"></script>
    <script type="text/javascript" src="../../Scripts/Jquery/jquery.form.js"></script>    
    <script type="text/javascript" src="js/test.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var options = {
                beforeSubmit: showRequest,
                success: showResponse,
                dataType: 'json',
                clearForm: true,
                error: function (request, message, ex) {
                    alert('错误：' + message);
                }
            };
            $('#qrForm').ajaxForm(options);
        });
        function showRequest(formData, jqForm, options) {
            return true;
        }
        function showResponse(responseText, statusText, xhr, $form) {
            if (responseText[0].count == 0) {
                alert(responseText[0].list[0].error);
                return false;
            }
            $("#img_qr").attr("src", responseText[0].list[0].imgurl);
            $("#txt_readqr").val(responseText[0].list[0].qrtext);
            return false;

        }
        function getQrImg() {
            var txt_qr = escape($.trim($("#txt_qr").val()));
            var qrEncoding = $("#Encoding").val();;
            var Level = $("#Level").val();;
            var txt_ver = $("#txt_ver").val();;
            var txt_size = $("#txt_size").val();;
            $.ajax({
                type: "GET",
                data: "cmd=set&txt_qr=" + txt_qr + "&qrEncoding=" + qrEncoding + "&Level=" + Level + "&txt_ver=" + txt_ver + "&txt_size=" + txt_size,
                url: "Ashx/test.ashx",
                dataType: 'text',
                beforeSend: function (x) {
                    x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
                },
                success: function (json) {
                    var dataObj = eval(json);
                    $("#qrimg").attr("src", dataObj[0].list[0].imgurl);
                    return false;
                },
                error: function (request, message, ex) {
                    alert("错误：" + message);
                }
            });
        }

    </script>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        #txt_qr
        {
            width: 632px;
        }
    </style>
</head>
<body>
    <div>
        <table class="style1">
            <tr>
                <td>
                    输入文字：
                </td>
                <td>
                    <input type="text" id="txt_qr" name="txt_qr" />
                </td>
            </tr>
            <tr>
                <td>
                    二维码图片
                </td>
                <td>
                    <img id="qrimg" alt="二维码图片" />
                </td>
            </tr>
            <tr>
                <td>
                    生成选项
                </td>
                <td>
                    Encoding:<select id="Encoding">
                        <option value="Byte">Byte</option>
                        <option value="AlphaNumeric">AlphaNumeric</option>
                        <option value="Numeric">Numeric</option>
                    </select>
                    Correction Level:<select id="Level">
                        <option value="M">M</option>
                        <option value="L">L</option>
                        <option value="Q">Q</option>
                        <option value="H">H</option>
                    </select>
                    Version:<input id="txt_ver" type="text" value="7" />(1-40) Size:<input id="txt_size"
                        type="text" value="4" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <input type="button" onclick="getQrImg();" value="生成二维码" />
                </td>
            </tr>
            <tr>
                <td>
                    <form id="qrForm" action="Ashx/test.ashx" method="post" enctype="multipart/form-data">
                    <input type="file" id="file_qr" name="file_qr" /><input type="submit" value="读取二维码" />
                    </form>
                </td>
                <td colspan="1">
                    <img id="img_qr" alt="要读取的图片" /><br />
                    <input id="txt_readqr" type="text" />
                </td>
            </tr>
        </table>
    </div>
</body>
</html>